<!DOCTYPE html>
<html lang="en">
<head>
<title>WebView4Delphi: uWVTypeLibrary: Interface ICoreWebView2Environment</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="generator" content="PasDoc 0.16.0-snapshot">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<link rel="StyleSheet" type="text/css" href="pasdoc.css">
</head>
<body>
<span id="ICoreWebView2Environment"></span><h1 class="cio">Interface ICoreWebView2Environment</h1>
<div class="sections">
<div class="one_section"><a class="section" href="#PasDoc-Description">Description</a></div><div class="one_section"><a class="section" href="#PasDoc-Hierarchy">Hierarchy</a></div><div class="one_section">Fields</div><div class="one_section"><a class="section" href="#PasDoc-Methods">Methods</a></div><div class="one_section">Properties</div></div>
<span id="PasDoc-Description"></span><h2 class="unit">Unit</h2>
<p class="unitlink">
<a href="uWVTypeLibrary.html">uWVTypeLibrary</a></p>
<h2 class="declaration">Declaration</h2>
<p class="declaration">
<code>type ICoreWebView2Environment = interface(IUnknown)</code></p>
<h2 class="description">Description</h2>
<p>
 Represents the WebView2 Environment. WebViews created from an environment run on the browser process specified with environment parameters and objects created from an environment should be used in the same environment. Using it in different environments are not guaranteed to be compatible and may fail. </p>
<p>


<p>&lt;see href=&quot;<a href="https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2environment">https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2environment</a>&quot;&gt;See the ICoreWebView2Environment article.)</p>
<span id="PasDoc-Hierarchy"></span><h2 class="hierarchy">Hierarchy</h2>
<ul class="hierarchy"><li class="ancestor">IUnknown</li>
<li class="thisitem">ICoreWebView2Environment</li></ul><h2 class="overview">Overview</h2>
<span id="PasDoc-Methods"></span><h3 class="summary">Methods</h3>
<table class="summary wide_list">
<tr class="list">
<td class="visibility"><a href="legend.html"><img  src="public.gif" alt="Public" title="Public"></a></td>
<td class="itemcode"><code>function <strong><a href="uWVTypeLibrary.ICoreWebView2Environment.html#CreateCoreWebView2Controller-HWND-ICoreWebView2CreateCoreWebView2ControllerCompletedHandler-">CreateCoreWebView2Controller</a></strong>(ParentWindow: HWND; const handler: <a href="uWVTypeLibrary.ICoreWebView2CreateCoreWebView2ControllerCompletedHandler.html">ICoreWebView2CreateCoreWebView2ControllerCompletedHandler</a>): HResult; stdcall;</code></td>
</tr>
<tr class="list2">
<td class="visibility"><a href="legend.html"><img  src="public.gif" alt="Public" title="Public"></a></td>
<td class="itemcode"><code>function <strong><a href="uWVTypeLibrary.ICoreWebView2Environment.html#CreateWebResourceResponse-IStream-SYSINT-PWideChar-PWideChar-ICoreWebView2WebResourceResponse-">CreateWebResourceResponse</a></strong>(const Content: IStream; StatusCode: SYSINT; ReasonPhrase: PWideChar; Headers: PWideChar; out Response: <a href="uWVTypeLibrary.ICoreWebView2WebResourceResponse.html">ICoreWebView2WebResourceResponse</a>): HResult; stdcall;</code></td>
</tr>
<tr class="list">
<td class="visibility"><a href="legend.html"><img  src="public.gif" alt="Public" title="Public"></a></td>
<td class="itemcode"><code>function <strong><a href="uWVTypeLibrary.ICoreWebView2Environment.html#Get_BrowserVersionString-PWideChar-">Get_BrowserVersionString</a></strong>(out versionInfo: PWideChar): HResult; stdcall;</code></td>
</tr>
<tr class="list2">
<td class="visibility"><a href="legend.html"><img  src="public.gif" alt="Public" title="Public"></a></td>
<td class="itemcode"><code>function <strong><a href="uWVTypeLibrary.ICoreWebView2Environment.html#add_NewBrowserVersionAvailable-ICoreWebView2NewBrowserVersionAvailableEventHandler-EventRegistrationToken-">add_NewBrowserVersionAvailable</a></strong>(const eventHandler: <a href="uWVTypeLibrary.ICoreWebView2NewBrowserVersionAvailableEventHandler.html">ICoreWebView2NewBrowserVersionAvailableEventHandler</a>; out token: <a href="uWVTypeLibrary.EventRegistrationToken.html">EventRegistrationToken</a>): HResult; stdcall;</code></td>
</tr>
<tr class="list">
<td class="visibility"><a href="legend.html"><img  src="public.gif" alt="Public" title="Public"></a></td>
<td class="itemcode"><code>function <strong><a href="uWVTypeLibrary.ICoreWebView2Environment.html#remove_NewBrowserVersionAvailable-EventRegistrationToken-">remove_NewBrowserVersionAvailable</a></strong>(token: <a href="uWVTypeLibrary.EventRegistrationToken.html">EventRegistrationToken</a>): HResult; stdcall;</code></td>
</tr>
</table>
<h2 class="description">Description</h2>
<h3 class="detail">Methods</h3>
<table class="detail wide_list">
<tr class="list">
<td class="visibility"><a href="legend.html"><img  src="public.gif" alt="Public" title="Public"></a></td>
<td class="itemcode"><span id="CreateCoreWebView2Controller-HWND-ICoreWebView2CreateCoreWebView2ControllerCompletedHandler-"></span><code>function <strong>CreateCoreWebView2Controller</strong>(ParentWindow: HWND; const handler: <a href="uWVTypeLibrary.ICoreWebView2CreateCoreWebView2ControllerCompletedHandler.html">ICoreWebView2CreateCoreWebView2ControllerCompletedHandler</a>): HResult; stdcall;</code></td>
</tr>
<tr><td colspan="2">
<p>
 Asynchronously create a new WebView.

<p>`parentWindow` is the `HWND` in which the WebView should be displayed and from which receive input. The WebView adds a child window to the provided window before this function returns. Z-order and other things impacted by sibling window order are affected accordingly. If you want to move the WebView to a different parent after it has been created, you must call put_ParentWindow to update tooltip positions, accessibility trees, and such.

<p>HWND_MESSAGE is a valid parameter for `parentWindow` for an invisible WebView for Windows 8 and above. In this case the window will never become visible. You are not able to reparent the window after you have created the WebView. This is not supported in Windows 7 or below. Passing this parameter in Windows 7 or below will return ERROR_INVALID_WINDOW_HANDLE in the controller callback.

<p>It is recommended that the app set Application User Model ID for the process or the app window. If none is set, during WebView creation a generated Application User Model ID is set to root window of `parentWindow`.

<p>\snippet AppWindow.cpp CreateCoreWebView2Controller

<p>It is recommended that the app handles restart manager messages, to gracefully restart it in the case when the app is using the WebView2 Runtime from a certain installation and that installation is being uninstalled. For example, if a user installs a version of the WebView2 Runtime and opts to use another version of the WebView2 Runtime for testing the app, and then uninstalls the 1st version of the WebView2 Runtime without closing the app, the app restarts to allow un-installation to succeed.

<p>\snippet AppWindow.cpp RestartManager

<p>The app should retry `CreateCoreWebView2Controller` upon failure, unless the error code is `HRESULT_FROM_WIN32(ERROR_INVALID_STATE)`. When the app retries `CreateCoreWebView2Controller` upon failure, it is recommended that the app restarts from creating a new WebView2 Environment. If a WebView2 Runtime update happens, the version associated with a WebView2 Environment may have been removed and causing the object to no longer work. Creating a new WebView2 Environment works since it uses the latest version.

<p>WebView creation fails with `HRESULT_FROM_WIN32(ERROR_INVALID_STATE)` if a running instance using the same user data folder exists, and the Environment objects have different `EnvironmentOptions`. For example, if a WebView was created with one language, an attempt to create a WebView with a different language using the same user data folder will fail.

<p>The creation will fail with `E_ABORT` if `parentWindow` is destroyed before the creation is finished. If this is caused by a call to `DestroyWindow`, the creation completed handler will be invoked before `DestroyWindow` returns, so you can use this to cancel creation and clean up resources synchronously when quitting a thread.

<p>In rare cases the creation can fail with `E_UNEXPECTED` if runtime does not have permissions to the user data folder. </p>
<h6 class="description_section">Attributes</h6>
<dl class="attributes">
  <dt>GUID['{B96D755E-0319-4E92-A296-23436F46A1FC}']</dt>
  <dd></dd>
</dl>
</td></tr>
</table>
<table class="detail wide_list">
<tr class="list">
<td class="visibility"><a href="legend.html"><img  src="public.gif" alt="Public" title="Public"></a></td>
<td class="itemcode"><span id="CreateWebResourceResponse-IStream-SYSINT-PWideChar-PWideChar-ICoreWebView2WebResourceResponse-"></span><code>function <strong>CreateWebResourceResponse</strong>(const Content: IStream; StatusCode: SYSINT; ReasonPhrase: PWideChar; Headers: PWideChar; out Response: <a href="uWVTypeLibrary.ICoreWebView2WebResourceResponse.html">ICoreWebView2WebResourceResponse</a>): HResult; stdcall;</code></td>
</tr>
<tr><td colspan="2">
<p>
 Create a new web resource response object. The `headers` parameter is the raw response header string delimited by newline. It is also possible to create this object with null headers string and then use the `ICoreWebView2HttpResponseHeaders` to construct the headers line by line. For more information about other parameters, navigate to [ICoreWebView2WebResourceResponse](/microsoft-edge/webview2/reference/win32/icorewebview2webresourceresponse).

<p>\snippet SettingsComponent.cpp WebResourceRequested0 \snippet SettingsComponent.cpp WebResourceRequested1 </p>
</td></tr>
</table>
<table class="detail wide_list">
<tr class="list">
<td class="visibility"><a href="legend.html"><img  src="public.gif" alt="Public" title="Public"></a></td>
<td class="itemcode"><span id="Get_BrowserVersionString-PWideChar-"></span><code>function <strong>Get_BrowserVersionString</strong>(out versionInfo: PWideChar): HResult; stdcall;</code></td>
</tr>
<tr><td colspan="2">
<p>
 The browser version info of the current `ICoreWebView2Environment`, including channel name if it is not the WebView2 Runtime. It matches the format of the `GetAvailableCoreWebView2BrowserVersionString` API. Channel names are `beta`, `dev`, and `canary`.

<p>The caller must free the returned string with `CoTaskMemFree`. See [API Conventions](/microsoft-edge/webview2/concepts/win32-api-conventions#strings).

<p>\snippet AppWindow.cpp GetBrowserVersionString </p>
</td></tr>
</table>
<table class="detail wide_list">
<tr class="list">
<td class="visibility"><a href="legend.html"><img  src="public.gif" alt="Public" title="Public"></a></td>
<td class="itemcode"><span id="add_NewBrowserVersionAvailable-ICoreWebView2NewBrowserVersionAvailableEventHandler-EventRegistrationToken-"></span><code>function <strong>add_NewBrowserVersionAvailable</strong>(const eventHandler: <a href="uWVTypeLibrary.ICoreWebView2NewBrowserVersionAvailableEventHandler.html">ICoreWebView2NewBrowserVersionAvailableEventHandler</a>; out token: <a href="uWVTypeLibrary.EventRegistrationToken.html">EventRegistrationToken</a>): HResult; stdcall;</code></td>
</tr>
<tr><td colspan="2">
<p>
 Add an event handler for the `NewBrowserVersionAvailable` event. `NewBrowserVersionAvailable` runs when a newer version of the WebView2 Runtime is installed and available using WebView2. To use the newer version of the browser you must create a new environment and WebView. The event only runs for new version from the same WebView2 Runtime from which the code is running. When not running with installed WebView2 Runtime, no event is run.

<p>Because a user data folder is only able to be used by one browser process at a time, if you want to use the same user data folder in the WebView using the new version of the browser, you must close the environment and instance of WebView that are using the older version of the browser first. Or simply prompt the user to restart the app.

<p>\snippet AppWindow.cpp NewBrowserVersionAvailable </p>
</td></tr>
</table>
<table class="detail wide_list">
<tr class="list">
<td class="visibility"><a href="legend.html"><img  src="public.gif" alt="Public" title="Public"></a></td>
<td class="itemcode"><span id="remove_NewBrowserVersionAvailable-EventRegistrationToken-"></span><code>function <strong>remove_NewBrowserVersionAvailable</strong>(token: <a href="uWVTypeLibrary.EventRegistrationToken.html">EventRegistrationToken</a>): HResult; stdcall;</code></td>
</tr>
<tr><td colspan="2">
<p>
 Remove an event handler previously added with `add_NewBrowserVersionAvailable`. </p>
</td></tr>
</table>
<hr><span class="appinfo"><em>Generated by <a href="https://pasdoc.github.io/">PasDoc 0.16.0-snapshot</a>. </em>
</span>
</body></html>
